// routes/materialsListRoutes.js
const express = require('express');
const router = express.Router();
const materialsListController = require('../controllers/materialsListController');

/**
 * @swagger
 * tags:
 *   name: 材料清单管理
 *   description: 材料清单的增删改查接口
 */

/**
 * @swagger
 * /api/materials:
 *   get:
 *     summary: 获取所有材料清单
 *     tags: [材料清单管理]
 *     responses:
 *       200:
 *         description: 返回材料清单列表
 */
router.get('/', materialsListController.getAllMaterials);

/**
 * @swagger
 * /api/materials/{id}:
 *   get:
 *     summary: 获取指定材料详情
 *     tags: [材料清单管理]
 *     parameters:
 *       - name: id
 *         in: path
 *         required: true
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 返回材料详情
 */
router.get('/:id', materialsListController.getMaterialById);

/**
 * @swagger
 * /api/materials:
 *   post:
 *     summary: 创建新材料
 *     tags: [材料清单管理]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name: { type: string }
 *               code: { type: string }
 *               specification: { type: string }
 *               supplier: { type: integer }
 *               project: { type: integer }
 *               type: { type: integer }
 *               expected_amount: { type: integer }
 *               purchase_amount: { type: integer }
 *               expected_cost: { type: number }
 *               cost: { type: number }
 *               unit: { type: string }
 *               rate: { type: number }
 *               purchaser: { type: integer }
 *               remark: { type: string }
 *               unit_price: { type: number }
 *     responses:
 *       200:
 *         description: 创建成功
 */
router.post('/', materialsListController.createMaterial);

/**
 * @swagger
 * /api/materials/{id}:
 *   put:
 *     summary: 更新材料信息
 *     tags: [材料清单管理]
 *     parameters:
 *       - name: id
 *         in: path
 *         required: true
 *         schema:
 *           type: integer
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *     responses:
 *       200:
 *         description: 更新成功
 */
router.put('/:id', materialsListController.updateMaterial);

/**
 * @swagger
 * /api/materials/{id}:
 *   delete:
 *     summary: 删除材料（软删除）
 *     tags: [材料清单管理]
 *     parameters:
 *       - name: id
 *         in: path
 *         required: true
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 删除成功
 */
router.delete('/:id', materialsListController.deleteMaterial);

module.exports = router;
